import router from '../../router'
import { setCookie } from '@/utils/cookies'
import { setLocal } from '@/utils/localStorage'
import {message} from "ant-design-vue"
import { loginApi } from '@/api/login.ts'
const initPageState = () => {
    return {
      userInfo: {
        _id: "",
        name: "",
        avatar: ""
      }
    };
  };
  const login = {
    state: initPageState(),
    mutations: {
    },
        actions: {
            loginAxios({},data:object) {
                console.log(data,889)
              loginApi(data).then((res:any) => {
                  if (res.code == 200) {
                    message.success( "登录成功", 2);
                    setCookie('admin_token', res.data.userList.token, 7)
                    setLocal('userMessage', JSON.stringify(res.data.userList))
                    router.push({ path: "/echarts"})
                  } else {
                    message.error( res.data.msg, 2);
                  }
                })
                .catch((error:any) => {
                  console.log(error);
                });
            }
          },

  };
  
  export default login;